﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;

namespace CC98.Xaml.Helpers
{
    public static class VisualHelper
    {
        public static T FindFirstChild<T>(this DependencyObject dpObj) where T : DependencyObject
        {
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(dpObj); ++i)
            {
                var child = VisualTreeHelper.GetChild(dpObj, i);
                if(child is T)
                {
                    return (T)child;
                }
                else
                {
                    child = child.FindFirstChild<T>();
                    if (child != null)
                        return (T)child;
                }
            }

            return null;
        }
    }
}
